﻿<!DOCTYPE HTML>
<html>
{include file='public/head'}
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 班级管理 <span
        class="c-gray en">&gt;</span> 班级列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">

    <div class="cl pd-5 bg-1 bk-gray mt-20" style="float: left;">
        <span class="l">
            <a href="javascript:;" onclick="admin_add('添加班级','{:url(\"admin/classroom/classadd\")}','800','500')" class="btn btn-primary radius">
            <i class="Hui-iconfont">&#xe600; </i>
            添加班级</a>
        </span>
    </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr>
            <th scope="col" colspan="10"> 班级列表</th>
        </tr>
        <tr class="text-c">
            <th width="30">ID</th>
            <th width="70">班级号</th>
            <th width="80">科目</th>
            <th width="100">开班时间</th>
            <th width="50">阶段</th>
            <th width="50">状态</th>
            <th width="20">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name='class.msg' id='vo'}
        <tr class="text-c">
            <td>{$vo.cid}</td>
            <td>
                <a href="javascript:;" onclick="classDeil('班级任职情况','{:url(\"admin/classroom/classDeil")}',{$vo.cid},'450','200')">
                {$vo.class_name}
                </a>
            </td>
            {switch $vo.subject}
            {case 1}
                <td>全栈</td>
            {/case}
            {case 2}
                <td>前端</td>
            {/case}
            {/switch}
            <td>{$vo.open_time|date="Y-m-d",###}</td>
            <td>
			<select class="select" name="stage" id="stage" size="1" onchange="stageChage('{$vo.cid}',this.value)">
				<option value="1" {in name="vo.stage" value="1"} selected {/in}>初级</option>
                <option value="2" {in name="vo.stage" value="2"} selected {/in}>中级</option>
                <option value="3" {in name="vo.stage" value="3"} selected {/in}>高级</option>
			</select>
            </span>

            </td>
            {if condition='$vo.status == 1'}
            <td class="td-status"><span class="label label-success radius">已开班</span></td>
            {else}
            <td class="td-status"><span class="label label-default radius">未开班</span></td>
            {/if}
            <td class="td-manage">
                {if condition='$vo.status == 1'}
                <a style="text-decoration:none" onClick="admin_stop(this,'{$vo.cid}')" href="javascript:;" title="结业"><i
                        class="Hui-iconfont">&#xe615;</i></a>
                {else}
                <a style="text-decoration:none" onClick="admin_start(this,'{$vo.cid}')" href="javascript:;"
                   title="开班"><i class="Hui-iconfont">&#xe631;</i></a>
                {/if}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
{include file='public/foot'} <!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/static/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/static/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    /*
        参数解释：
        title	标题
        url		请求的url
        id		需要操作的数据id
        w		弹出层宽度（缺省调默认值）
        h		弹出层高度（缺省调默认值）
    */
    /*管理员-增加*/
    function admin_add(title, url, w, h) {
        layer_show(title, url, w, h);
    }
    function classDeil(title,url,id,w,h) {
        layer_show(title,url+'?cid='+id,w,h);
    }
    function stageChage(cid,val){
        var url = "{:url('admin/classroom/stagechage')}";
        var urls = "{:url('admin/classroom/ChooseTeacher')}";
        $.ajax({
            type:'get',
            data:'stage='+val+'&cid='+cid,
            dataType:'json',
            url:url,
            success:function (data) {
                if (data.status == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000,});
                    layer_show('添加老师',urls+'?cid='+cid,500,200);
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }
            },
        })
    }
    /*管理员-删除*/
    function admin_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                data: 'id=' + id,
                url: '{:url("admin/classroom/classdel")}',
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1) {
                        $(obj).parents("tr").remove();
                        layer.msg(data.msg, {icon: 1, time: 1000});
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1000});
                    }
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }

    /*管理员-编辑*/
    function admin_edit(title, url, id, w, h) {
        layer_show(title, url + '?cid=' + id, w, h);
    }

    /*管理员-停用*/
    function admin_stop(obj, id) {
        layer.confirm('确认要结业吗？', function (index) {
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: 'post',
                data: 'id=' + id,
                dataType: 'json',
                url: '{:url("admin/classroom/ClassLock")}',
                success: function (data) {
                    if (data.status == 1) {
                        $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,' + id + ')" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
                        $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">未开班</span>');
                        $(obj).remove();
                        layer.msg('未开班!', {icon: 5, time: 1000});
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1000});
                    }
                }
            })
        });
    }

    /*管理员-启用*/
    function admin_start(obj, id) {
        layer.confirm('确认要开班吗？', function (index) {
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: 'post',
                data: 'id=' + id,
                dataType: 'json',
                url: '{:url("admin/classroom/ClassLock")}',
                success: function (data) {
                    if (data.status == 1) {
                        $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,' + id + ')" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
                        $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已开班</span>');
                        $(obj).remove();
                        layer.msg('已开班!', {icon: 6, time: 1000});
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
</script>
</body>
</html>